import time
from selenium.webdriver import Keys
import page
from base.base import Base


class PageBuyProduct(Base):
    # 点击登录链接
    def page_click_login_link(self):
        self.base_click_element(page.login_link)

    # 输入账号
    def page_input_username(self, username):
        self.base_in_element_input(page.login_username, username)

    # 输入密码
    def page_input_password(self, password):
        self.base_in_element_input(page.login_password, password)

    # 输入验证码
    def page_input_verify(self, verify):
        self.base_in_element_input(page.login_verify, verify)

    # 点击ENTER进行登录
    def page_click_keyboard_ENTER_btn(self):
        self.base_keyboard_action(page.product_login_btn, key=Keys.ENTER)

    # 获得提示信息
    def page_get_hint_info(self):
        return self.base_get_element_text(page.product_hint_info)

    # 获取验证码图片
    def page_get_verify_img(self):
        verify_img = self.base_get_element_img(page.login_verify_img)
        return verify_img

    # 获得截屏
    def page_get_screenshot(self):
        self.base_get_img()

    # 判断是否登录成功
    def page_login_is_or_not_success(self):
        try:
            self.base_find_element(page.login_logout_link)
            return True
        except:
            return False

    def page_click_logout_link(self):
        self.base_click_element(page.login_logout_link)

    def page_product_login(self, accounts, pwd, verify):
        self.page_input_username(accounts)
        self.page_input_password(pwd)
        self.page_input_verify(verify)
        self.page_click_keyboard_ENTER_btn()
